/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
			All Rights Reserved.
			Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\defgroup   sync_start_a2dp Sync Start A2DP
\ingroup    audio_domain
\brief      Synchronised start for A2DP.

The A2DP synchronised start can work in various modes which are determined by the state of the Mirror profile
(see MirrorProfile_GetA2dpStartMode() and mirror_profile_a2dp_start_mode_t).

For all the modes when audio is synchronised actual start of the audio is delayed for the time required
to synchronise both earbuds.

In non Q2Q mode graph won't be started until some audio data is present.

The mirror profile will call SyncStartA2dp_StartMirroring() when A2DP audio source is routed on both earbuds.
Calling that function sets up the audio synchronisation infrastructure.
Audio synchronisation infrastructure are two clock conversion transforms connected between the RTP operator
and the L2CAP connecting both earbuds. It will generate a message indicating that audio streams are in sync.
Note that the audio synchronisation infrastructure is not only responsible for the synchronised start,
but also for synchronisation of audio between earbuds
(i.e. ensuring that the audio on the left earbud is in sync with the audio on the right earbud).

For MIRROR_PROFILE_A2DP_START_PRIMARY/SECONDARY_SYNCHRONISED modes the TTP for the RTP operator
will be configured in such a way that the audio will start rendering at the same time on both earbuds.

For MIRROR_PROFILE_A2DP_START_PRIMARY/SECONDARY_SYNC_UNMUTE modes both earbuds will be muted until
the secondary will send the time instant when both of earbuds should unmute.
Moreover in UNMUTE modes are a fallback modes should SYNCHRONISED modes fail.
*/

#ifndef SYNC_START_A2DP_H_
#define SYNC_START_A2DP_H_

#include "sync_start_a2dp_types.h"

#include <rtime.h>
#include <message.h>
#include <operator.h>
#include <csrtypes.h>

/*!@{*/

/*! \brief Initialise function
    \param init_tast[in] Unused
	\return TRUE if initialisation successful, else FALSE
*/
bool SyncStartA2dp_Init(Task init_task);

/*! \brief Start the A2DP audio graph when in sync
    \param source[in] Source of the audio
*/
void SyncStartA2dp_StartGraphWhenInSync(Source source);

/*! \brief Start A2DP mirroring
    \param sink[in] Sink associated with A2DP 
*/
void SyncStartA2dp_StartMirroring(Sink sink);

/*! \brief Stop A2DP mirroring
    \param Source[in] Source associated with A2DP 
*/
void SyncStartA2dp_StopMirroring(Source source);

/*! \brief Set A2DP start time
    \param clock[in] time to start
*/
void SyncStartA2dp_SetStartTime(uint32 clock);

/*! \brief Set A2DP unmute time
    \param unmute_time[in] time to unmute the audio
*/
void SyncStartA2dp_SetUnmuteTime(rtime_t unmute_time);

/*! \brief Set the sync operator ID
    \param sync_op_id[in] operator ID
*/
void SyncStartA2dp_SetSyncOperatorId(Operator sync_op_id);

/*! \brief Force Sink Audio to be synchronized  */
void SyncStartA2dp_ForceSinkAudioSynchronized(void);

/*! \brief Start Audio synchronisation and set the mode to Synchronised*/
void SyncStartA2dp_StartAudioSync(bool is_primary, uint32_t latency_in_us);

/*! \brief Pause Audio synchronisation */
void SyncStartA2dp_PauseAudioSync(void);

/*! \brief Resume Audio synchronisation */
void SyncStartA2dp_ResumeAudioSync(void);

/*! \brief Audio synchronisation is complete 
    \return TRUE if audio sync is complete, else FALSE*/
bool SyncStartA2dp_IsAudioSyncComplete(void);

/*!@}*/

#endif /* SYNC_START_A2DP_H_ */
